import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

// store名称统统用use开头
// defineStore 参数1 仓库名称  参数2 函数
export const useCounterStore = defineStore('counter', () => {
  // 类比state
  const count = ref(100)
  // 类比getters
  const doubleCount = computed(() => count.value * 2)
  // mutations
  const update = () => count.value++
  // actions
  const asyncUpdate = () => {
    setTimeout(() => {
      count.value++
    }, 3000);
  }
  return { count, doubleCount, update, asyncUpdate}
})